#include<iostream>  
#include<string.h>  
using namespace std;  
  
class Str_Num{  
public:  
    Str_Num(const string &s):str(s),len(str.length()){}  
  
    int val(int &pos,bool &ok)const{  
        int val=0,t=pos;  
        ok=true;  
        for(;pos<len&&str[pos]>='0'&&str[pos]<='9';++pos)  
            val=val*10+str[pos]-'0';  
        if(pos==t)  
            ok=false;  
        return val;  
    }  
  
private:  
    string str;  
    int len;  
};  
  
  
class Calculator{  
public:  
    Calculator(const string& s):str_n(s),eval(s),len(eval.length()){}  
      
    int value()const{  
        int val=0,pos=0;  
        bool ok=true;  
        val=term1(pos,ok);  
        if(!ok||pos!=len)  
            throw exception("Format of calculate string is invalid,or divisor is zero!!");  
        return val;  
    }  
  
private:  
    int term1(int &pos,bool &ok)const{  
        int a=term2(pos,ok),b=0;  
        while(pos<len&&ok){  
            if(eval[pos]=='+'||eval[pos]=='-'){  
                char op=eval[pos];  
                ++pos;  
                b=term2(pos,ok);  
                if(op=='+')  
                    a+=b;  
                else a-=b;  
            }  
            else return a;  
        }  
        return a;  
    }  
    int term2(int &pos,bool &ok)const{  
        int a=term3(pos,ok),b;  
        while(pos<len&&ok){  
            if(eval[pos]=='*'||eval[pos]=='/'){  
                char op=eval[pos];  
                ++pos;  
                b=term3(pos,ok);  
                if(op=='*')  
                    a*=b;  
                else{  
                    if(b==0){  
                        ok=false;  
                        return a;  
                    }  
                    a/=b;  
                }  
            }  
            else return a;  
        }  
        return a;  
    }  
  
    int term3(int &pos,bool &ok)const{  
        bool negative=false;  
        int result;  
        if(eval[pos]=='-'){  
            negative=true;  
            ++pos;  
        }  
        if(eval[pos]=='('){  
            ++pos;  
            result=term1(pos,ok);  
            if(eval[pos]!=')'){  
                ok=false;  
                return result;  
            }  
            ++pos;  
        }  
        else result=str_n.val(pos,ok);  
        if(negative)  
            result*=-1;  
        return result;  
  
    }  
    Str_Num str_n;  
    string eval;  
    int len;  
};  
  
int main(){  
    string test="2*((11-1)-12*(6/(6-3)))";  
    Calculator cal(test);  
    try{  
        cout<<cal.value()<<endl;  
    }catch(exception e){  
        cout<<e.what()<<endl;  
    }  
    return 0;  
}  